{extend name="base" /}
{block name="body"}
<style type="text/css">
.mleft {
    margin-right: 10px;
}
</style>
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">账号管理</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
            <div class="layui-form-item">
                <form class="layui-form layui-form-pane" action="{:url('admin/player/logininfo')}" method="get">
                    <div class="layui-inline mleft">
                        <label class="layui-form-label">数据查询</label>
                        <div class="layui-input-inline">
                            <input type="text" name="keyword" value="{:input('keyword')}" placeholder="输入玩家账号/IP/代理账号" class="layui-input">
                        </div>
                    </div>
                    <!-- <div class="layui-inline mleft"> -->
                        <!-- <label class="layui-form-label">玩家IP</label> -->
                        <!-- <div class="layui-input-inline"> -->
                            <!-- <input type="text" name="ip" value="{:input('ip')}" placeholder="请输入IP地址" class="layui-input"> -->
                        <!-- </div> -->
                    <!-- </div>				 -->
                    <div class="layui-inline mleft">
                      <label class="layui-form-label">游戏区服</label>
                      <div class="layui-input-inline" style="width: 120px;">
                        <select name="game" lay-filter="game" id="game">
                            <option value="">请选择游戏</option>
						    {foreach name="game_list" item="vo"}
							<option value="{$vo.id}"{if condition="$data.game == $vo.id"} selected{/if}>{$vo.gname}</option>
							{/foreach}
                        </select>
                      </div>
                      <div class="layui-input-inline" style="width: 120px;">
                        <select name="area" id="area" lay-verify="required" lay-filter="area" lay-search="" {if condition="$data.game == null"} disabled{/if}>
                          <option value="">请选择区服</option>
                        </select>
						<input type="hidden" id="areaname" value="{:input('area')}">
                      </div>
                    </div>
                    <div class="layui-inline mleft">
                        <label class="layui-form-label">范围选择</label>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input name="starttime" value="{:input('starttime')}" class="layui-input" placeholder="开始日" id="LAY_range_s">
                        </div>
                        <div class="layui-form-mid">-</div>
                        <div class="layui-input-inline" style="width: 100px;">
                          <input name="endtime" value="{:input('endtime')}" class="layui-input" placeholder="截止日" id="LAY_range_e">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn">搜索</button>
                    </div>
                </form>
                </div>
                <hr>

                <table class="layui-table">
                    <thead>
                    <tr>
					    <th style="width: 30px;">ID</th>
                        <th style="width: 60px;">玩家账号</th>
                        <th style="width: 50px;">所属代理</th>
                        <!-- <th style="width: 30px;">代理ID</th> -->
                        <th style="width: 60px;">游戏名称</th>
                        <th style="width: 60px;">区服名称</th>
                        <th style="width: 80px;">登录IP</th>
                        <th style="width: 80px;">注册时间</th>
						<th style="width: 80px;">最后登录</th>
						<th style="width: 30px;">状态</th>
                    </tr>
                    </thead>
                    <tbody>
						{foreach name="reg_list" item="vo"}
						<tr>
							<td>{$vo.id}</td>
							<td>{$vo.uname}</td>
							<td>{$vo.aname}</td>
							<!-- <td>{$vo.agent}</td> -->
							<td>{$vo.gname}</td>
							<td>{$vo.sname}</td>
							<td>{$vo.login_ip}</td>
							<td>{$vo.reg_time}</td>
							<td>{$vo.last_time}</td>
						    <td class="layui-form">
						        <div style="margin-top:-8px;">
						            <input data-url="{:url('admin/player/check')}" data="{$vo['id']}" type="checkbox" name="checkbtn" lay-filter="checkbtn" lay-skin="switch" lay-text="正常|封停"  {eq name="$vo['status']" value="1"}checked=""{/eq}>
						        </div>
						    </td>
						</tr>
						{/foreach}
                    </tbody>
                </table>
                <!--分页-->
				{$reg_list->render()}
            </div>    
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script>
layui.use(['form', 'laydate'], function(){
    var form = layui.form()
     ,laydate = layui.laydate;
    var start = {
      min: laydate.now(-730)
      ,max: laydate.now()
      ,istoday: false
      ,choose: function(datas){
        end.min = datas; //开始日选好后，重置结束日的最小日期
        end.start = datas //将结束日的初始值设定为开始日
      }
    };
    
    var end = {
      min: laydate.now()
      ,max: '2099-06-16 23:59:59'
      ,istoday: false
      ,choose: function(datas){
        start.max = datas; //结束日选好后，重置开始日的最大日期
      }
    };
    document.getElementById('LAY_range_s').onclick = function(){
      start.elem = this;
      laydate(start);
    }
    document.getElementById('LAY_range_e').onclick = function(){
      end.elem = this
      laydate(end);
    }
	//监听开启开关
      form.on('switch(checkbtn)', function(data){
        var url  = $(this).attr('data-url');
    	var date = $(this).attr('data');
    	var type = this.checked ? 1:0;
    	$.post(url,{id:date,type:type},function(info){
    	    layer.msg(info.msg);	
    		})
    });
    //监听开启开关
    form.on('select(game)', function(data){
	    if (data.value){
		    var gid  =  data.value;
            $("#area").removeAttr("disabled");
		    $('#area').empty();	
			$.get("/admin/player/getgarea",{gid:gid}, function(info){
			$("#area").append('<option value="">请选择区服</option>');
			    if (info.length > 0){
                    for (var i=0;i<info.length;i++){
				        var sid   = info[i].id;
				    	var sname = info[i].sname;
				    	$("#area").append('<option value="' + sid  + '">' + sname + '</option>');
                    }
				}else{
				    layer.msg('获取区服列表失败,可能没有区服数据');
				}
				form.render('select');
			});
		}
    });
});
    $(document).ready(function(){
	    var game = $('#game option:selected').val();
		var areaname = $("#areaname").val();
        if (game !== ""){
		    $.get("/admin/player/getgarea",{gid:game}, function(info){
                if (info.length > 0){
                    for (var i=0;i<info.length;i++){
				        var sid   = info[i].id;
				    	var sname = info[i].sname;
				    	if (sid == areaname){
				    	    $("#area").append('<option value="' + sid  + '"  selected="">' + sname + '</option>');
				    	}else{
				    	    $("#area").append('<option value="' + sid  + '">' + sname + '</option>');
				    	}
                    }
				}else{
				    layer.msg('获取区服列表失败,您可能没有申请区服');
				}
				form.render('select');
			});
		   
		} 
			
    });

</script>
{/block}